package com.gui.juc.pool;

import com.gui.utils.Sleeper;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Slf4j
public class ThreadPoolDemo3 {

    public static void main(String[] args) {

        ExecutorService threadPool = Executors.newSingleThreadExecutor();

        for (int i = 0; i < 10; i++) {
            int j = i;
            threadPool.submit(() -> {
                if (j % 2 ==0 && j > 0) {
                    throw new RuntimeException("执行出错");
                }
                log.debug("执行任务：{}", j);
            });
        }

        threadPool.shutdown();
        Sleeper.sleep(3);
        log.debug("执行结束...");
    }
}
